import {
    GetRefundRecords,
    TabRefundRecord,
    GrantRefundBack,
    GetTransferTypes,
    GetMoneyWent
} from '@/services/finance/list';
import {catchException} from '@/utils/utils';
export default {
    namespace: 'recordList',

    state: {
        recordList: [],
        transferTypesList:[],
        moneyWentList: []
    },

    effects: {

        // 获取订单列表
        *GetRefundRecords({payload, callBack}, {call, put}) {
            const data = yield call(GetRefundRecords, payload);
            yield catchException(function* (){
                if(data.Code === 0) {
                    yield put({
                        type: 'saveGetRefundRecords',
                        payload: {
                            dataList: data.Data,
                        },
                    });
                    callBack && callBack.success(data);
                } else {
                    callBack && callBack.error(data)
                } 
            })             
        },

        // 获取转账方式列表
        *GetTransferTypes({payload, callBack}, {call, put}) {
            const data = yield call(GetTransferTypes, payload);
            yield catchException(function* (){
                if(data.Code === 0) {
                    yield put({
                        type: 'saveGetTransferTypes',
                        payload: {
                            dataList: data.Data,
                        },
                    });
                    callBack && callBack.success(data);
                } else {
                    callBack && callBack.error(data)
                }
            }) 
            
    },

    // 获取订单维权钱款去向
    *GetMoneyWent({payload, callBack}, {call, put}) {
        const data = yield call(GetMoneyWent, payload);
        yield catchException(function* (){
            if(data.Code === 0) {
                yield put({
                    type: 'saveGetMoneyWent',
                    payload: {
                        dataList: data.Data,
                    },
                });
                callBack && callBack.success(data);
            } else {
                callBack && callBack.error(data)
            }
        })         
    },

    //原路
    *GrantRefundBack({payload, callBack}, {call, put}) {
        const data = yield call(GrantRefundBack, payload);
        yield catchException(function* (){
            if(data.Code === 0) {
                callBack && callBack.success(data);
            } else {
                callBack && callBack.error(data)
                } 
        })         
    },

    //标记
    *TabRefundRecord({payload, callBack}, {call, put}) {
        const data = yield call(TabRefundRecord, payload);
        yield catchException(function* (){
            if(data.Code === 0) {
                callBack && callBack.success(data);
            } else {
                callBack && callBack.error(data)
            } 
        })             
    },
},

    reducers: {
        saveGetRefundRecords(state, {payload}) {
            return {
                ...state,
                recordList: payload.dataList,
            };
        },
        saveGetTransferTypes(state, {payload}) {
            return {
                ...state,
                transferTypesList: payload.dataList,
            };
        },
        saveGetMoneyWent(state, {payload}) {
            return {
                ...state,
                moneyWentList: payload.dataList,
            };
        },
    }
}